package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.RoleDao;
import com.ChenYaRou.www.po.Role;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;

/**
 * @ClassName RoleDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 22:04
 * @Version 1.0
 **/
public class RoleDaoImpl implements RoleDao {
    /**
     * 查找role集合
     * @param role 仅赋值条件的role
     * @return 街区集合
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public Role select(Role role) throws IllegalAccessException, SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectSimple(GenerateSql.getInstance().select(role), Role.class);
    }
    /**
     * update role
     * @param newRole role需要更新的值
     * @param  oldRole old role
     * @return 成功与否
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(Role newRole, Role oldRole) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newRole,oldRole));
    }
    /**
     * 插入role
     * @param role 新role
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(Role role) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(role));
    }
}
